package jihyun51.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

import java.awt.CardLayout;

import javax.swing.JTextField;

import java.awt.Color;
import java.awt.SystemColor;
import java.awt.Font;

import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTabbedPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class AComp extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JPanel panel3 = new JPanel();
	private JTabbedPane mainPane = new JTabbedPane(JTabbedPane.TOP);
	private JTextField id_txtF;
	private JTextField pw_txtF;
	private JLabel id_label;
	private JLabel pw_label;
	private JButton login_btn;
	private JButton join_btn;
	private JLabel my_icon;
	private JLabel nick_output;
	private JButton logout_btn;
	private CardLayout cards=new CardLayout(0, 0);

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			AComp dialog = new AComp();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public AComp() {
		setTitle(" :: 고급 컴퍼넌트 ::");
		setBounds(100, 100, 640, 480);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JPanel top = new JPanel();
			top.setPreferredSize(new Dimension(120, 100));
			contentPanel.add(top, BorderLayout.NORTH);
			top.setLayout(new BorderLayout(0, 0));
			{
				final JPanel cardPane = new JPanel();
				cardPane.setBackground(SystemColor.control);
				cardPane.setPreferredSize(new Dimension(210, 10));
				top.add(cardPane, BorderLayout.EAST);
				cardPane.setLayout(cards);
				
				JPanel logoutPane = new JPanel();
				logoutPane.setBackground(new Color(250, 240, 230));
				cardPane.add(logoutPane, "login");
				{
					id_label = new JLabel("아이디");
					id_label.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
				}
				{
					id_txtF = new JTextField();
					id_txtF.setColumns(10);
				}
				{
					pw_label = new JLabel("비밀번호");
					pw_label.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
				}
				{
					pw_txtF = new JTextField();
					pw_txtF.setColumns(10);
				}
				{
					login_btn = new JButton("로그인");
					login_btn.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							String id=id_txtF.getText();
							String pwd=pw_txtF.getText();
							if(id.equals("")||pwd.equals("")){
								JOptionPane.showMessageDialog(null, "아이디나 비밀번호를 입력하세요");

							}
							if(id.equals("asdf")&&pwd.equals("1234")){
								JOptionPane.showMessageDialog(null, "아이디와 비밀번호가 확인");
							cards.show(cardPane,"logout");
							mainPane.setEnabledAt(2, true);
							//탭활성/ 비활성은 setEnabledAt()을 이용 
							//3번째 탭을 비활성함
							}
							else 
								JOptionPane.showMessageDialog(null, "아이디와 비밀번호가 다릅니다,");
						
						//cards : 카드 레이아웃
						//cardPane : 카드레이아웃이 적용된 패널
						//logout : cardPane에 보여줄 패널 이름
						}
					});
				}
				{
					join_btn = new JButton("회원가입");
				}
				GroupLayout gl_logoutPane = new GroupLayout(logoutPane);
				gl_logoutPane.setHorizontalGroup(
					gl_logoutPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_logoutPane.createSequentialGroup()
							.addGroup(gl_logoutPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_logoutPane.createSequentialGroup()
									.addGap(26)
									.addComponent(id_label)
									.addGap(18)
									.addComponent(id_txtF, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_logoutPane.createParallelGroup(Alignment.TRAILING)
									.addGroup(Alignment.LEADING, gl_logoutPane.createSequentialGroup()
										.addGap(20)
										.addComponent(pw_label)
										.addPreferredGap(ComponentPlacement.UNRELATED)
										.addComponent(pw_txtF, 0, 0, Short.MAX_VALUE))
									.addGroup(Alignment.LEADING, gl_logoutPane.createSequentialGroup()
										.addGap(27)
										.addComponent(login_btn)
										.addGap(5)
										.addComponent(join_btn))))
							.addGap(20))
				);
				gl_logoutPane.setVerticalGroup(
					gl_logoutPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_logoutPane.createSequentialGroup()
							.addGap(7)
							.addGroup(gl_logoutPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(id_label)
								.addComponent(id_txtF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(10)
							.addGroup(gl_logoutPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(pw_label)
								.addComponent(pw_txtF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGap(6)
							.addGroup(gl_logoutPane.createParallelGroup(Alignment.LEADING)
								.addComponent(login_btn)
								.addComponent(join_btn)))
				);
				logoutPane.setLayout(gl_logoutPane);
				
				JPanel loginPane = new JPanel();
				loginPane.setBackground(new Color(255, 228, 181));
				cardPane.add(loginPane, "logout");
				{
					my_icon = new JLabel("");
					my_icon.setIcon(new ImageIcon(AComp.class.getResource("/images/icon/Ps.png")));
				}
				{
					nick_output = new JLabel("이름이나옴");
				}
				{
					logout_btn = new JButton("로그아웃");
					logout_btn.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							cards.show(cardPane, "login");
						}
					});
				}
				GroupLayout gl_loginPane = new GroupLayout(loginPane);
				gl_loginPane.setHorizontalGroup(
					gl_loginPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_loginPane.createSequentialGroup()
							.addGap(13)
							.addComponent(my_icon)
							.addGap(5)
							.addComponent(nick_output)
							.addGap(5)
							.addComponent(logout_btn))
				);
				gl_loginPane.setVerticalGroup(
					gl_loginPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_loginPane.createSequentialGroup()
							.addGap(5)
							.addComponent(my_icon))
						.addGroup(gl_loginPane.createSequentialGroup()
							.addGap(13)
							.addComponent(nick_output))
						.addGroup(gl_loginPane.createSequentialGroup()
							.addGap(9)
							.addComponent(logout_btn))
				);
				loginPane.setLayout(gl_loginPane);
			}
			{
				JLabel topLogo = new JLabel("-");
				topLogo.setPreferredSize(new Dimension(400, 50));
				topLogo.setIcon(new ImageIcon(AComp.class.getResource("/images/background/top.jpg")));
				top.add(topLogo, BorderLayout.WEST);
			}
		}
		{
			
			contentPanel.add(mainPane, BorderLayout.CENTER);
			{
				JPanel panel1 = new JPanel();
				FlowLayout flowLayout = (FlowLayout) panel1.getLayout();
				panel1.setBackground(new Color(245, 222, 179));
				mainPane.addTab("기본검색", new ImageIcon(AComp.class.getResource("/images/icon/Cup.png")), panel1, null);
				mainPane.setBackgroundAt(0, new Color(255, 228, 181));
				mainPane.setForegroundAt(0, new Color(0, 0, 0));
				mainPane.setEnabledAt(0, true);
			}
			{
				JPanel panel2 = new JPanel();
				panel2.setBackground(new Color(224, 255, 255));
				mainPane.addTab("상세검색", null, panel2, null);
				mainPane.setBackgroundAt(1, new Color(224, 255, 255));
			}
			{
				JPanel panel3 = new JPanel();
				panel3.setBackground(new Color(230, 230, 250));
				mainPane.addTab("마이페이지", null, panel3, null);
				mainPane.setBackgroundAt(2, new Color(220, 220, 220));
				mainPane.setEnabledAt(2, false);
			}
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
